package com.zggk.iroad.land;

import android.app.Activity;
import com.alibaba.fastjson.JSON;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.zggk.iroad.api.MyAppliCation;
import com.zggk.iroad.api.Urls;
import com.zggk.iroad.callback.StringDialogCallback;
import com.zggk.iroad.mvp.BasePresenterImpl;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class LandPresenter extends BasePresenterImpl<LandContract.View> implements LandContract.Presenter{
    @Override
    public void Land(String userName, String passWord,Activity activity) {
        OkGo.<String>post(Urls.YNIP + "MobileLogin")
                .params("userName", userName)
                .params("passWord", passWord)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LandInfo landInfo = JSON.parseObject(response.body(),LandInfo.class);
                        if (mView == null)
                            return;
                        if (landInfo.getState().equals("1")){
                            mView.getLand(landInfo);
                        }else {
                            mView.onRequestError(landInfo.getMSG());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        mView.onRequestError(response.body());
                    }
                });
    }
    @Override
    public void getName() {
        OkGo.<String>get(Urls.IP + "/apiserver/apisno/patrolForApp/systemlist")
                .params("token", "Bearer$" + MyAppliCation.spUtils.getString("Token"))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        mView.getNames(response.body());
                    }
                });
    }
}
